package com.yxplearn.mybatisplus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxplearn.mybatisplus.mapper.UserMapper;
import com.yxplearn.mybatisplus.mapper.UserRecordMapper;
import com.yxplearn.mybatisplus.pojo.User;
import com.yxplearn.mybatisplus.pojo.UserRecord;
import com.yxplearn.mybatisplus.service.UserRecordService;
import com.yxplearn.mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    UserRecordService userRecordService;

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class}, propagation = Propagation.REQUIRED)
    public void saveOne(User user) {
//        try {
            UserRecord userRecord = new UserRecord();
            userRecord.setPlayerName("yxp1233");
            userRecord.setMapValue(new HashMap<>());
            userRecord.setListValue(new ArrayList<>());
            userRecordService.saveOne(userRecord);
//        } catch (Exception exception) {
//            exception.printStackTrace();
//        }

        try {
            userMapper.insert(user);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

    }
}
